package com.cswangdao.controller.admin;


import com.cswangdao.domain.dto.AdPageDTO;
import com.cswangdao.domain.model.MarketAd;
import com.cswangdao.result.PageResult;
import com.cswangdao.result.Result;
import com.cswangdao.service.AdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/ad")
@Slf4j
public class AdminAdController {

    @Autowired
    private AdService adService;

    /**
     * @description: 广告信息分页查询
     * @param: request, response
     * @return: void
     */
    @GetMapping("/list")
    public Result<PageResult<MarketAd>> list(AdPageDTO pageDTO) {
        log.info("广告信息分页查询：{}", pageDTO);
        PageResult<MarketAd> pageResult = adService.pageQueryInfo(pageDTO);
        return Result.success(pageResult);
    }

    /**
     * @description: 新增广告信息
     * @param: request, response
     * @return: void
     */
    @PostMapping("/create")
    public Result<MarketAd> create(@RequestBody MarketAd ad) {
        log.info("新增广告信息：{}", ad);
        MarketAd res = adService.addAd(ad);
        return Result.success(res);
    }

    /**
     * @description: 更新广告信息
     * @param: request, response
     * @return: void
     */
    @PostMapping("/update")
    public Result<MarketAd> update(@RequestBody MarketAd ad) {
        log.info("更新广告信息：{}", ad);
        MarketAd res = adService.updateById(ad);
        return Result.success(res);
    }

    /**
     * @description: 删除广告信息
     * @param: request, response
     * @return: void
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody MarketAd ad) {
        log.info("删除广告信息：{}", ad);
        adService.deleteById(ad.getId());
        return Result.success();
    }

}
